package agendamento;

import java.util.ArrayList;
import java.util.List;

import javax.swing.JComboBox;
import javax.swing.JFormattedTextField;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

import com.toedter.calendar.JDateChooser;

import hibernate.dao.*;
import hibernate.entity.*;

public class CtrlAgendamento {

	private ClienteDAO dao = new ClienteDAO();
	private AgendamentoDAO ag = new AgendamentoDAO();
	
	public void preencheCB(JComboBox cb){
		for(Cliente cliente : dao.getLista()){
			cb.addItem(cliente.getNome());
		}
	}
	
	public void agendar(JComboBox cb, JDateChooser dt , JComboBox horario, JTextField servico){
		Agendamento agenda = new Agendamento();
		Servico s = new Servico();
		s.setId_servico((long) 9);
		//agenda.setCliente(dao.importaDados((String) cb.getSelectedItem()));
		agenda.setHorario((String)horario.getSelectedItem());
		agenda.setData(dt.getDate());
		//agenda.setServico(s);
		ag.adicionarAgendamento();
		
		JOptionPane.showMessageDialog(null, "Agendamento incluido com sucesso!");
	}
	
	public void validaHorario(JComboBox cb, JDateChooser dt , JComboBox horario, JTextField servico){
		Agendamento agenda = new Agendamento();
		agenda.setHorario((String)horario.getSelectedItem());
		agenda.setData(dt.getDate());
		if(ag.validaHorario()){
			JOptionPane.showMessageDialog(null, "Horario reservado! Escolha outro horario ou data");
			limparCampos(cb, dt, horario, servico);
		}
		else{
			agendar(cb,dt,horario,servico);
		}
		
	}
	
	public void limparCampos(JComboBox cb, JDateChooser dt , JComboBox horario, JTextField servico){
		cb.setSelectedIndex(0);
		dt.setDate(null);
		horario.setSelectedItem(0);
		servico.setText("");
		
		}
	
}
